package top.tagao.yygh.hosp.controller.api;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.tagao.yygh.common.result.Result;
import top.tagao.yygh.hosp.service.DepartmentService;
import top.tagao.yygh.hosp.service.HospitalService;
import top.tagao.yygh.hosp.service.HospitalSetService;
import top.tagao.yygh.hosp.service.ScheduleService;
import top.tagao.yygh.model.hosp.Hospital;
import top.tagao.yygh.model.hosp.HospitalSet;
import top.tagao.yygh.model.hosp.Schedule;
import top.tagao.yygh.vo.hosp.DepartmentVo;
import top.tagao.yygh.vo.hosp.HospitalQueryVo;
import top.tagao.yygh.vo.hosp.ScheduleOrderVo;
import top.tagao.yygh.vo.order.SignInfoVo;

import java.util.List;
import java.util.Map;

/**
 * @author fu-xiao-liu
 * @Date 2022/3/7 21:13
 */
@Api(tags = "医院管理接口 前台前端")
@RestController
@RequestMapping("/api/hospital/hospital")
public class HospitalApiController {

    @Autowired
    private HospitalService hospitalService;

    @Autowired
    private DepartmentService departmentService;

    @Autowired
    private ScheduleService scheduleService;

    @Autowired
    private HospitalSetService hospitalSetService;

    @ApiOperation(value = "查询医院列表")
    @GetMapping("findHospitalList/{page}/{limit}")
    public Result  findHospitalList(@PathVariable Integer page,
                                   @PathVariable Integer limit,
                         HospitalQueryVo hospitalQueryVo) {
        //显示上线的医院
        //hospitalQueryVo.setStatus(1);
        Page<Hospital> pageModel = hospitalService.selectHospPage(page, limit, hospitalQueryVo);
        return Result.ok(pageModel);
    }

    @ApiOperation(value = "根据医院名称获取医院列表")
    @GetMapping("findByHospitalName/{hosname}")
    public Result findByHospitalName(
            @ApiParam(name = "hosname", value = "医院名称", required = true)
            @PathVariable String hosname){
        List<Hospital> list = hospitalService.findHospitalListByHosname(hosname);
        return Result.ok(list);
    }


    @ApiOperation(value = "根据医院编号查询科室信息")
    @GetMapping("getDepartmentList/{hoscode}")
    public Result getDepartmentList(
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode) {

        List<DepartmentVo>  departmentVos = departmentService.findDepartmentTree(hoscode);
        return Result.ok(departmentVos);
    }

    @ApiOperation(value = "根据医院编号获取医院详情")
    @GetMapping("getHospitalDetail/{hoscode}")
    public Result getScheduleDetail(
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode) {

        Map<String, Object> map = hospitalService.getHospitalDetail(hoscode);
        return Result.ok(map);
    }

    @ApiOperation(value = "医院 科室 获取可预约排班数据")
    @GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public Result getBookingScheduleRule(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Integer  page,
            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Integer  limit,
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode,
            @ApiParam(name = "depcode", value = "科室code", required = true)
                            @PathVariable String depcode){

        Map<String, Object> rule = scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode);

        return Result.ok(rule);
    }

    @ApiOperation(value = "获取排班数据")
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public Result findScheduleList(

            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode,
            @ApiParam(name = "depcode", value = "科室code", required = true)
            @PathVariable String depcode,
            @ApiParam(name = "workDate", value = "排班日期", required = true)
            @PathVariable String workDate
    ){
        List<Schedule> detailSchedule = scheduleService.getDetailSchedule(hoscode, depcode, workDate);
        return  Result.ok(detailSchedule);
    }

    @ApiOperation(value = "根据排班id获取排班数据")
    @GetMapping("getSchedule/{scheduleId}")
    public Result getSchedule(@PathVariable String scheduleId){
       Schedule schedule = scheduleService.getById(scheduleId);
        return  Result.ok(schedule);
    }

    @ApiOperation(value = "根据排班id获取预约下单数据")
    @GetMapping("inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(
            @ApiParam(name = "scheduleId", value = "排班id", required = true)
            @PathVariable("scheduleId") String scheduleId) {
        return scheduleService.getScheduleOrderVo(scheduleId);
    }


    @ApiOperation(value = "获取医院签名信息")
    @GetMapping("inner/getSignInfoVo/{hoscode}")
    public SignInfoVo getSignInfoVo(
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable("hoscode") String hoscode) {
        return hospitalSetService.getSignInfoVo(hoscode);
    }



}
